package com.nciae.controller;


import com.nciae.po.DormitoryHead;
import com.nciae.service.IDormitoryHeadService;
import com.nciae.service.IDormitoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Guoliyu
 * @since 2022-03-30
 */
@RestController
@RequestMapping("/dormitoryHead")
public class DormitoryHeadController {

    @Autowired
    private IDormitoryHeadService dormitoryHeadService;

    @GetMapping
    public ResponseEntity<List<DormitoryHead>> findAll(
            @RequestParam("index")int index,
            @RequestParam("capacity")int capacity,
            @RequestParam("username")String username
    ) {
        return ResponseEntity.ok(dormitoryHeadService.findAll(index, capacity, username));
    }

    @PostMapping
    public ResponseEntity<Boolean> add(@RequestBody DormitoryHead dormitoryHead) {
        dormitoryHeadService.add(dormitoryHead);
        return ResponseEntity.ok(true);
    }

    @PutMapping
    public ResponseEntity<Boolean> update(@RequestBody DormitoryHead dormitoryHead) {
        dormitoryHeadService.update(dormitoryHead);
        return ResponseEntity.ok(true);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> delete(@PathVariable("id")Long id) {
        dormitoryHeadService.delete(id);
        return ResponseEntity.ok(true);
    }

}
